package com.spring.boot.springBoot.shiro.controller;

import com.spring.boot.springBoot.shiro.entity.UserInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;


/**
 * Created by pactera on 2017/9/28.
 */
@Controller
public class LoginController {


    @GetMapping({"/","/index"})
    public String index(){
        return "index";
    }

    @GetMapping(value="/login")
    public String loginHtml(){
        return "login";
    }

    @PostMapping(value="/login")
    public String login(UserInfo userInfo){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(userInfo.getUserName(),userInfo.getPassword());
        subject.login(usernamePasswordToken);
        return "index";
    }
}
